package by.fedorenko.sample.services.impl;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.fedorenko.sample.dataaccess.AppartmentTypeDao;
import by.fedorenko.sample.datamodel.AppartmentType;
import by.fedorenko.sample.services.AppartmentTypeService;

@Service
public class AppartmentTypeServiceImpl implements AppartmentTypeService{
	private static final Logger LOGGER = LoggerFactory.getLogger(AppartmentTypeServiceImpl.class);

	@Inject
	private AppartmentTypeDao appartmentTypeDao;
	
	@PostConstruct
	private void init() {
		// this method will be called by Spring after bean instantiation. Can be
		// used for any initialization process.
		LOGGER.info("Instance of ProductService is created. Class is: {}", getClass().getName());
	}
	@Override
	public AppartmentType get(Long id) {
		AppartmentType entity = appartmentTypeDao.getById(id);
		return entity;
		
	}

	@Override
	public void saveOrUpdate(AppartmentType appartmentType) {
		if (appartmentType.getId() == null) {
			LOGGER.debug("Save new: {}", appartmentType);
			appartmentTypeDao.insert(appartmentType);
		} else {
			LOGGER.debug("Update: {}", appartmentType);
			appartmentTypeDao.update(appartmentType);
		}
		
	}

	@Override
	public void delete(AppartmentType appartmentType) {
		LOGGER.debug("Remove: {}", appartmentType);
		appartmentTypeDao.delete(appartmentType.getId());
	}

	@Override
	public void deleteAll() {
		LOGGER.debug("Remove all appartmentTypes");
		appartmentTypeDao.deleteAll();
		
	}

}
